
package yunxiangchuan

import (
	"context"
	"github.com/flipped-aurora/gin-vue-admin/server/global"
	"github.com/flipped-aurora/gin-vue-admin/server/model/yunxiangchuan"
    yunxiangchuanReq "github.com/flipped-aurora/gin-vue-admin/server/model/yunxiangchuan/request"
)

type AlbumDecorationsService struct {}
// CreateAlbumDecorations 创建相册装饰管理记录
// Author [yourname](https://github.com/yourname)
func (albumDecorationsService *AlbumDecorationsService) CreateAlbumDecorations(ctx context.Context, albumDecorations *yunxiangchuan.AlbumDecorations) (err error) {
	err = global.GVA_DB.Create(albumDecorations).Error
	return err
}

// DeleteAlbumDecorations 删除相册装饰管理记录
// Author [yourname](https://github.com/yourname)
func (albumDecorationsService *AlbumDecorationsService)DeleteAlbumDecorations(ctx context.Context, id string) (err error) {
	err = global.GVA_DB.Delete(&yunxiangchuan.AlbumDecorations{},"id = ?",id).Error
	return err
}

// DeleteAlbumDecorationsByIds 批量删除相册装饰管理记录
// Author [yourname](https://github.com/yourname)
func (albumDecorationsService *AlbumDecorationsService)DeleteAlbumDecorationsByIds(ctx context.Context, ids []string) (err error) {
	err = global.GVA_DB.Delete(&[]yunxiangchuan.AlbumDecorations{},"id in ?",ids).Error
	return err
}

// UpdateAlbumDecorations 更新相册装饰管理记录
// Author [yourname](https://github.com/yourname)
func (albumDecorationsService *AlbumDecorationsService)UpdateAlbumDecorations(ctx context.Context, albumDecorations yunxiangchuan.AlbumDecorations) (err error) {
	err = global.GVA_DB.Model(&yunxiangchuan.AlbumDecorations{}).Where("id = ?",albumDecorations.Id).Updates(&albumDecorations).Error
	return err
}

// GetAlbumDecorations 根据id获取相册装饰管理记录
// Author [yourname](https://github.com/yourname)
func (albumDecorationsService *AlbumDecorationsService)GetAlbumDecorations(ctx context.Context, id string) (albumDecorations yunxiangchuan.AlbumDecorations, err error) {
	err = global.GVA_DB.Where("id = ?", id).First(&albumDecorations).Error
	return
}
// GetAlbumDecorationsInfoList 分页获取相册装饰管理记录
// Author [yourname](https://github.com/yourname)
func (albumDecorationsService *AlbumDecorationsService)GetAlbumDecorationsInfoList(ctx context.Context, info yunxiangchuanReq.AlbumDecorationsSearch) (list []yunxiangchuan.AlbumDecorations, total int64, err error) {
	limit := info.PageSize
	offset := info.PageSize * (info.Page - 1)
    // 创建db
	db := global.GVA_DB.Model(&yunxiangchuan.AlbumDecorations{})
    var albumDecorationss []yunxiangchuan.AlbumDecorations
    // 如果有条件搜索 下方会自动创建搜索语句
    
	err = db.Count(&total).Error
	if err!=nil {
    	return
    }

	if limit != 0 {
       db = db.Limit(limit).Offset(offset)
    }

	err = db.Find(&albumDecorationss).Error
	return  albumDecorationss, total, err
}
func (albumDecorationsService *AlbumDecorationsService)GetAlbumDecorationsPublic(ctx context.Context) {
    // 此方法为获取数据源定义的数据
    // 请自行实现
}
